var a = require("../../utils/config.js");

Page({
    data: {
        taskList: [],
        page: 1,
        sidx: "CreateTime",
        sord: "Desc",
        isEnd: !1,
        address: "",
        taskType: "",
        taskTypeList: [ "全部" ]
    },
    onLoad: function(t) {
        var s = this;
        s.loadDataSource(), wx.showLoading({
            mask: !0
        }), wx.request({
            url: a.urlList.API_TASK_GET_TASK_TYPE,
            method: "GET",
            success: function(a) {
                wx.hideLoading(), 200 == a.data.status ? s.setData({
                    taskTypeList: s.data.taskTypeList.concat(a.data.data)
                }) : wx.showToast({
                    title: a.data.message,
                    icon: "none"
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.data.page = 1, this.loadDataSource();
    },
    onReachBottom: function() {
        this.data.isEnd || (this.data.page++, this.loadDataSource());
    },
    onShareAppMessage: function() {},
    loadDataSource: function() {
        var t = this, s = wx.getStorageSync("userId");
        1 == this.data.page && (t.setData({
            isEnd: !1
        }), t.data.taskList = []), wx.request({
            url: a.urlList.API_TASK_GET_TASK_LIST,
            data: {
                page: this.data.page,
                rows: 10,
                sidx: t.data.sidx,
                sord: t.data.sord,
                userId: s || "",
                taskType: t.data.taskType,
                address: t.data.address
            },
            header: {
                "content-type": "application/json"
            },
            success: function(a) {
                t.setData({
                    taskList: t.data.taskList.concat(a.data.data)
                }), a.data.data.length < 10 && (t.data.page--, t.setData({
                    isEnd: !0
                })), wx.stopPullDownRefresh();
            }
        });
    },
    sortTime: function() {
        this.setData({
            sidx: "CreateTime",
            sord: "Desc"
        }), wx.startPullDownRefresh();
    },
    sortPrice: function() {
        var a = this;
        a.setData({
            sidx: "TaskPrice",
            sord: "Desc" == a.data.sord ? "Asc" : "Desc"
        }), wx.startPullDownRefresh();
    },
    goToTaskDetial: function(a) {
        wx.navigateTo({
            url: "../task/taskDetail?id=" + a.currentTarget.dataset.id
        });
    },
    chooseAddress: function(a) {
        var t = "全部" == a.detail.value[0] ? "" : a.detail.value[0], s = "全部" == a.detail.value[1] ? "" : a.detail.value[1], e = "全部" == a.detail.value[2] ? "" : a.detail.value[2];
        this.setData({
            address: t + s + e
        }), this.onPullDownRefresh();
    },
    chooseTaskType: function(a) {
        var t = this;
        t.setData({
            taskType: "全部" == t.data.taskTypeList[a.detail.value] ? "" : t.data.taskTypeList[a.detail.value]
        }), t.onPullDownRefresh();
    }
});